package com.zyl.blog.common.domain.rbac.dto;

import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.validation.annotation.Validated;

import java.util.Map;

/**
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.common.domain.rbac.dto
 * @ClassName: UserDTO
 * @Description:
 * @Author FinalFantasy
 * @Date 2025/9/9-08:53
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Validated
public class UserDTO {

    /**
     * 用户ID：仅编辑时必填
     */
    @NotNull(
            message = "用户ID不能为空",
            groups = UpdateGroup.class
    )
    private Long userId;

    /**
     * 用户名：新增时必填，编辑时可选但需校验长度
     */
    @NotBlank(
            message = "用户名不能为空",
            groups = AddGroup.class
    )
    @Size(
            min = 3,
            max = 20,
            message = "用户名长度需在3-20字符之间",
            groups = {AddGroup.class, UpdateGroup.class}
    )
    private String username;

    /**
     * 密码：仅新增时必填
     */
    @NotBlank(
            message = "密码不能为空",
            groups = AddGroup.class
    )
    @Pattern(
            regexp = "^(?=.*[a-zA-Z])(?=.*\\W).{8,}$",
            message = "密码必须包含字母和特殊字符，且长度至少为8位",
            groups = AddGroup.class
    )
    private String password;

    /**
     * 邮箱：新增时必填，编辑时可选但需校验格式
     */
    @NotBlank(
            message = "邮箱不能为空",
            groups = AddGroup.class
    )
    @Email(
            message = "邮箱格式不正确",
            groups = {AddGroup.class, UpdateGroup.class}
    )
    private String email;

    /**
     * 手机号：新增时必填，编辑时可选但需校验格式
     */
    @NotBlank(
            message = "手机号不能为空",
            groups = AddGroup.class
    )
    @Pattern(
            regexp = "^1[3-9]\\d{9}$",
            message = "手机号格式不正确",
            groups = {AddGroup.class, UpdateGroup.class}
    )
    private String phone;

    /**
     * 昵称：新增编辑时可选
     */
    private String nickname;

    /**
     * 真实姓名：新增编辑时可选
     */
    private String realName;

    /**
     * 性别：新增时必填，编辑时可选
     */
    @NotNull(
            message = "性别不能为空",
            groups = AddGroup.class
    )
    private Integer gender;

    /**
     * 生日：新增编辑时可选
     */
    private String birthday;

    /**
     * 身份证号
     */
    @Pattern(
            regexp = "^\\d{18}$",
            message = "身份证号格式不正确",
            groups = {AddGroup.class, UpdateGroup.class}
    )
    private String idCard;

    /**
     * 头像地址
     */
    private String avatar;

    /**
     * 个人简介
     */
    private String bio;

    /**
     * 所在地
     */
    private String location;

    /**
     * 详细地址
     */
    private String address;

    /**
     * 邮编
     */
    private String postCode;

    /**
     * 网站
     */
    private String website;

    /**
     * 社交链接
     */
    private Map<String, String> socialLinks;

    /**
     * 状态：新增时必填，编辑时可选
     */
    @NotNull(
            message = "用户状态不能为空",
            groups = AddGroup.class
    )
    private Integer status;

    /**
     * 角色：新增时必填，编辑时可选
     */
    @NotBlank(
            message = "角色不能为空",
            groups = AddGroup.class
    )
    private String role;

    public interface AddGroup {}

    public interface UpdateGroup {}
}